package com.sky.rabc.aop.annotation;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
@Slf4j
public class AssignValueAspect {
    @Around(value = "@annotation(AssignValue)")
    public Object assignValue(ProceedingJoinPoint joinPoint) throws Throwable {
        //获取注解对象
        AssignValue annotation = ((MethodSignature) joinPoint.getSignature()).getMethod()
                .getAnnotation(AssignValue.class);
        String value = joinPoint.getArgs()[0]+ " + " + annotation.value();
        Object result = joinPoint.proceed(new Object[]{value});
        log.info("annotation method:{}", (joinPoint.getSignature()).getName());
        return result;
    }
}
